/**
 * @param {number[]} cookies
 * @param {number} k
 * @return {number}
 */
 var distributeCookies = function(cookies, k) {
  const n = cookies.length
  let sum = cookies.reduce((pre,cur) => pre+cur, 0)
  cookies.sort((a,b) => a-b)
  if(k === n) {
    return cookies[n-1]
  }
  let ans = Infinity
  for(let i = 1; i<1<<n; i++) {
    let c = 0
    for(let j = 0; j<n; j++) {
      if((i & (1<<j)) > 0) {
        c += cookies[j]
      }
    }
    if(c >= sum/k && c >= cookies[n-1]) {
      ans = Math.min(ans, c)
    }
  }
  return ans
};